The logic behind investing